const App = {
    data() {
        return {
            photo,
            form: {
                villageNumber: '',
                action: 0,
                SQLSerialNumber: 't_village_activities_mini',
                PaginationNumber: 1, //页码
                RowAmount: 10,
                Condition: window.btoa(unescape(encodeURIComponent("232723100001"))),
                ExtensionCondition: window.btoa(unescape(encodeURIComponent("AND NOW() BETWEEN village_activities.Registration_Start_Datetime AND village_activities.Registration_End_Datetime"))),
            },
            tabs: ['报名中','进行中', '已结束'],
            ACCESSTOKEN: '',
            total: 0,
            loading: false,
            tableData: [],
        }
    },
    beforeCreate() {
        function setRem() {
            const designWidth = 750; // 设计稿宽度（rpx）
            const maxWidth = 540; // 可选：限制最大宽度（如手机端常见值）
            const screenWidth = Math.min(window.innerWidth, maxWidth);
            const scale = screenWidth / designWidth;
            document.documentElement.style.fontSize = scale + 'px';
        }
        setRem();//1rem = 0.5px 对标小程序在 375px 宽的屏幕上，1rpx = 0.5px（因为 750rpx / 375px = 2）
        window.addEventListener('resize', setRem);
        function debounce(func, delay) { //防抖
            let timeout;
            return function () {
                clearTimeout(timeout);
                timeout = setTimeout(() => func.apply(this, arguments), delay);
            };
        }
        window.addEventListener('scroll', debounce(() => {
            // 可视区域高度 + 滚动条滚动距离 >= 页面总高度（考虑浮点数精度问题）
            if (window.innerHeight + window.scrollY >= document.documentElement.scrollHeight - 1) {
                this.loading = true;//提示
                if (this.total > this.tableData.length) {
                    this.form.PaginationNumber += 1;
                    this.getList(this.form);
                }
            }
        }, 200));
    },
    mounted() {
        let URL = window.location.href;
        this.ACCESSTOKEN = getQueryObject(URL, 'ACCESSTOKEN');
        let villageNumber = getQueryObject(URL, 'villageNumber');
        this.form.Condition = window.btoa(unescape(encodeURIComponent(villageNumber)))
        this.getList(this.form);
    },
    methods: {
        handleTab(index) {
            this.form.action = index;
            this.form.PaginationNumber = 1;
            if (index == 0) {
                this.form.ExtensionCondition = window.btoa(unescape(encodeURIComponent("AND NOW() BETWEEN village_activities.Registration_Start_Datetime AND village_activities.Registration_End_Datetime")));
            } else if (index == 1) {
                this.form.ExtensionCondition = window.btoa(unescape(encodeURIComponent("AND NOW() BETWEEN village_activities.Activity_Datetime AND village_activities.Activity_End_Datetime")));
            } else if (index == 2){
                this.form.ExtensionCondition = window.btoa(unescape(encodeURIComponent("AND NOW() > village_activities.Activity_End_Datetime")));
            }
            this.loading = false;
            this.tableData = [];
            this.getList(this.form);
        },
        getList(data) {
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                method: "post",
                data,
                success: (res) => {
                    this.total = res.TotalRows;//总数量
                    this.loading = false;
                    this.tableData = [...this.tableData, ...res.Rows];
                },
                complete: (XMLHttpRequest) => {
                    if (XMLHttpRequest.status == 302) {
                        wx.miniProgram.navigateTo({
                            url: miniProgram,
                        })
                    }
                },
            });
        },
        handleClick(item) {//前往查看详情
            // window.location.href = './detail.html?nodeKey=' + item.Village_Activity_SerialNumber + '&ACCESSTOKEN=' + this.ACCESSTOKEN;
            wx.miniProgram.navigateTo({
                url: '/villageResite/detailActivity/detailActivity?status=2&id=' + item.Village_Activity_SerialNumber,
            })
        }
    },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");